package com.gun.management.module.raffle.dal.mysql.lottery;

import java.util.*;

import com.gun.management.framework.common.pojo.PageResult;
import com.gun.management.framework.mybatis.core.query.LambdaQueryWrapperX;
import com.gun.management.framework.mybatis.core.mapper.BaseMapperX;
import com.gun.management.module.raffle.controller.app.vo.AppLotteryRespVO;
import com.gun.management.module.raffle.dal.dataobject.lottery.LotteryDO;
import org.apache.ibatis.annotations.*;
import com.gun.management.module.raffle.controller.admin.lottery.vo.*;

/**
 * 抽奖信息 Mapper
 *
 * @author 测试账号
 */
@Mapper
public interface LotteryMapper extends BaseMapperX<LotteryDO> {

    @Insert("INSERT INTO raffle_lottery(`name`, `category_id`, `bg_picture`, `total_times`, `day_total_times`, `expense_score`, `max_prize_count`, `status`, `content`) VALUES " +
            "(#{entity.name}, #{entity.categoryId}, #{entity.bgPicture}, #{entity.totalTimes}, #{entity.dayTotalTimes}, #{entity.expenseScore}, #{entity.maxPrizeCount}, #{entity.status},   #{entity.content});")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    public void insertAndGetId(@Param("entity") LotteryDO entity);

    default PageResult<LotteryDO> selectPage(LotteryPageReqVO reqVO) {
        return selectPage(reqVO,  new LambdaQueryWrapperX<LotteryDO>()
                .likeIfPresent(LotteryDO::getName, reqVO.getName())
                .eqIfPresent(LotteryDO::getStatus, reqVO.getStatus())
                .betweenIfPresent(LotteryDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(LotteryDO::getCreateTime));
    }


    default List<LotteryDO> selectListByStatus(Integer status) {
        return selectList(LotteryDO::getStatus, status);
    }




    @Select({"<script>select A.id,A.name,A.category_id,A.status   from raffle_lottery A  " +
            "<where>" +
            "<if test='lotteryIdList != null and lotteryIdList.size() >0  '>" +
            " and A.id in  " +
            "    <foreach item=\"item\" index=\"index\" collection=\"lotteryIdList\" open=\"(\" separator=\",\" close=\")\">  " +
            "        #{item} " +
            " </foreach> " +
            "</if>" +
            "   and  A.status = 0 " +
            "</where>" +
            " order by A.id asc " +
            "</script>"}
    )
    public List<AppLotteryRespVO>  selectAppLotteryList(@Param("lotteryIdList") List<Long> lotteryIdList);


    @Select({"<script>select A.id,A.name,A.category_id,A.status,A.content   from raffle_lottery A  " +
            "<where>" +
            "<if test='categoryId != null  '>" +
            " and A.category_id  = #{categoryId} " +
            " </if>" +
            "  and  A.status = 0 " +
            "</where>" +
            " order by A.id asc " +
            "</script>"}
    )
    public AppLotteryRespVO selectAppLotteryRespVO(@Param("categoryId")  Long  categoryId);
}